package sx.convert;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class Gui extends JFrame implements ActionListener{
	private JTextField dollar=new JTextField("0.0",20);
	private JTextField euro=new JTextField(20);
	private JTextField rmb=new JTextField(20);
	private JButton submit=new JButton("�ύ");
	private JButton reset=new JButton("����");
	public Gui(){
		super("��Ԫ����Ƽ�ת��");
		this.setLocation(300, 300);
		this.setSize(280, 220);
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		this.add(new JLabel("����ת����������",JLabel.RIGHT));
		this.add(dollar);this.add(new JLabel("��Ԫ"));
		this.add(new JLabel("�ɶһ���",JLabel.RIGHT));this.add(euro);this.add(new JLabel("ŷԪ"));
		this.add(new JLabel("�ɶһ���",JLabel.RIGHT));this.add(rmb);this.add(new JLabel("�����"));
		this.add(submit);this.add(reset);
		euro.setEditable(false);submit.addActionListener(this);
		rmb.setEditable(false);reset.addActionListener(this);
		dollar.addActionListener(this);
		euro.setHorizontalAlignment(JTextField.RIGHT);
		rmb.setHorizontalAlignment(JTextField.RIGHT);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String resEuro="";
		String resRmb="";
		String d=dollar.getText();
		if(e.getSource()==reset){
			dollar.setText("");
		}
		
		resEuro=Convert.calc(d, "euro");  //��̬����ת��
		resRmb=Convert.calc(d, "rmb");
		
		euro.setText(resEuro);
		rmb.setText(resRmb);
	}

}
